// 栈是一种操作受限的线性数据结构
// 栈的实现，后进先出LIFO（Last in, First out）：

class Stack {
    constructor(...args) {
        this.stack = [...args];
    }

    // Modifiers
    push(...items) {
        return this.stack.push(...items);
    }

    pop() {
        return this.stack.pop();
    }

    // Element access
    peek() {
        return this.isEmpty() ? undefined : this.stack[this.size() - 1];
    }

    isEmpty() {
        return this.size() === 0;
    }

    size() {
        return this.stack.length;
    }
}

let stack = new Stack();
stack.push('a', 'b')
console.log(stack);
console.log(stack.pop());
console.log(stack.pop());
console.log(stack.pop());
console.log(stack.pop());
console.log(stack);

